BEGIN;
	CREATE FUNCTION compare_wordstrings_normalize(TEXT,TEXT) RETURNS NUMERIC AS $$
		WITH
			words1 AS (SELECT regexp_split_to_table(lower($1),E'(\\s|,)+') AS word,count(*) AS wordCount GROUP BY word),
			words2 AS (SELECT regexp_split_to_table(lower($2),E'(\\s|,)+') AS word,count(*) AS wordCount GROUP BY word)
		SELECT
			coalesce(
				(SELECT sum(words1.wordCount+words2.wordCount) AS countIntersects FROM words1 INNER JOIN words2 USING(word))
				/((SELECT sum(wordCount) FROM words1)+(SELECT sum(wordCount) FROM words2))
			,0);
	$$ LANGUAGE sql;
END;
